var ajaxHelper = require("../../utils/ajaxhelp");
const serviceUrl = getApp().globalData.serviceUrl;
let token = wx.getStorageSync('token');

/**根据地区获取学校列表 */
const getSchoolByPAC = (provinceName, cityName, areaName) => {
	token = wx.getStorageSync('token');
	return ajaxHelper.promiseRequst(serviceUrl + "/api/School/GetSchoolByProviceCityCounty", {
		'Authorization': 'Bearer ' + token
	}, "GET", {
		provice: provinceName,
		city: cityName,
		area: areaName
	})
}

/**获取学校详细信息 */
const getSchoolDetail = (schoolId) => {
	token = wx.getStorageSync('token');
	return ajaxHelper.promiseRequst(serviceUrl + "/api/School/GetSchoolById", {}, "GET", {
		schoolId: schoolId
	})
}

/**根据类型获取学校列表 */
const getSchoolListByParams = (school = {}) => {
	token = wx.getStorageSync('token');
	return ajaxHelper.promiseRequst(serviceUrl + "/api/School/GetSchool", {
		'Authorization': 'Bearer ' + token
	}, "GET", school)
}

/**根据搜索框获取学校列表 */
const getSchoolListBySearch = (school = {}) => {
	token = wx.getStorageSync('token');
	return ajaxHelper.promiseRequst(serviceUrl + "/api/School/QuerySchool", {
		'Authorization': 'Bearer ' + token
	}, "GET", school)
}


/**修改学校信息 */
const modSchoolInfo = (schoolInfo = {}) => {
	token = wx.getStorageSync('token');
	return ajaxHelper.promiseRequst(serviceUrl + "/api/School/Post", {
		'Authorization': 'Bearer ' + token
	}, "POST", schoolInfo)
}

/**保存学校信息 */
const saveSchoolInfo = (schoolInfo = {}) => {
	token = wx.getStorageSync('token');
	return ajaxHelper.promiseRequst(serviceUrl + "/api/School/Put", {
		'Authorization': 'Bearer ' + token
	}, "POST", schoolInfo)
}

module.exports = {
	getSchoolByPAC,
	getSchoolDetail,
	getSchoolListByParams,
	saveSchoolInfo,
	modSchoolInfo,
	getSchoolListBySearch,
}
